--[[ 编码: JX-108-15 名称: 巨星任务-巨星空料箱出库-空料箱出库 作者:HAN 日期:2025-1-29 级别:项目 函数: CallEmptyBoxOut 功能: -- 从料箱库计算出一个空的巨星料箱 -- 创建‘巨星出库’作业 更改记录: --]] jx_base= require( "jx_base" ) function CallEmptyBoxOut ( strLuaDEID ) local nRet, strRetInfo local strUserLogin, strUserName nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前操作人员信息失败! "..strUserLogin ) end -- 获取【巨星空料箱出库】的输入信息 nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_STATION_NO", "Number" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local station = lua.Get_StrAttrValue( obj_attrs[1].value ) local empty_box_num = lua.Get_NumAttrValue( obj_attrs[2].value ) -- 需要出的空料箱数量 if ( station == '' ) then mobox.setInfo( strLuaDEID, "需要确定站台信息!") return end if ( empty_box_num <= 0 ) then mobox.setInfo( strLuaDEID, "空料箱数量必须大于 0 !") return end -- 数据准备 -- box_type = 2 就是巨星的料箱 local storage_arae = wms_base.Get_sConst( strLuaDEID, "料箱库存储区" ) local station_data local loc_code, cntr_code, n local start_loc, end_loc nRet, station_data = jx_base.Get_Station_ExtData( strLuaDEID, station ) if ( nRet ~= 0 ) then return 2, station_data end local storage_cache_arae = lua.Get_StrAttrValue( station_data.entry_area_code ) if ( storage_cache_arae == '') then mobox.setInfo( strLuaDEID, "'机台-"..station.."'没有定义入库口区域编码信息!" ) return end loc_code = station_data.loc_code nRet, end_loc = wms_wh.GetLocInfo( loc_code ) if ( nRet ~= 0 ) then mobox.setInfo( strLuaDEID, "获取货位'"..loc_code.."'信息失败!"..end_loc ) return end -- 申请空料箱 local trans_id = lua.guid() -- 容器锁事务 local start_loc local nCount = 0 local empty_box_list = {} nRet, empty_box_list = jx_base.Get_EmptyBox_Loc( strLuaDEID, trans_id, storage_arae, 2, empty_box_num ) if ( nRet ~= 0 ) then wms.wms_AbortCntrLockTrans( trans_id ) lua.Error( strLuaDEID, debug.getinfo(1), empty_box_list ) end lua.Debug( strLuaDEID, debug.getinfo(1), "呼出巨星空料箱--->empty_box_list", empty_box_list ) nCount = #empty_box_list if ( nCount == 0 ) then mobox.setInfo( strLuaDEID, "库区"..area_code.."没有巨星空料箱!" ) return end for n = 1, nCount do cntr_code = empty_box_list[n].cntr_code loc_code = empty_box_list[n].loc_code -- 创建巨星任务和出库搬运作业 nRet, start_loc = wms_wh.GetLocInfo( loc_code ) if ( nRet ~= 0 ) then wms.wms_AbortCntrLockTrans( trans_id ) lua.Error( strLuaDEID, debug.getinfo(1), "获取货位'"..loc_code.."'信息失败!"..start_loc ) end -- 创建巨星任务 jx_task = m3.AllocObject(strLuaDEID, "JX_Task") jx_task.start_wh_code = start_loc.wh_code jx_task.start_area_code = storage_arae jx_task.start_loc_code = start_loc.code jx_task.station = station jx_task.end_wh_code = end_loc.wh_code jx_task.end_area_code = end_loc.area_code jx_task.end_loc_code = end_loc.code jx_task.cntr_code = cntr_code jx_task.source_sys = "巨星" jx_task.priority = 1 jx_task.task_type = "巨星空料箱出库" jx_task.create_method = "HH-WMS" nRet, jx_task = m3.CreateDataObj(strLuaDEID, jx_task) if (nRet ~= 0) then wms.wms_AbortCntrLockTrans( trans_id ) lua.Error(strLuaDEID, debug.getinfo(1), "创建任务池失败!" .. jx_task) end operation = m3.AllocObject(strLuaDEID,"Operation") operation.bs_state = 8 operation.start_wh_code = start_loc.wh_code operation.start_area_code = start_loc.area_code operation.start_loc_code = start_loc.code operation.end_wh_code = end_loc.wh_code operation.end_area_code = end_loc.area_code operation.end_loc_code = end_loc.code operation.lock_cntr = "N" -- 作业启动时不需要锁容器 operation.cntr_code = cntr_code operation.op_type = wms_base.Get_nConst(strLuaDEID, "作业类型-出库") operation.op_def_name = "巨星出库" operation.bs_type = "JX_Task" operation.bs_no = jx_task.sour_no operation.source_sys = "巨星" nRet, operation = m3.CreateDataObj( strLuaDEID, operation ) if ( nRet ~= 0 ) then wms.wms_AbortCntrLockTrans( trans_id ) lua.Error( strLuaDEID, debug.getinfo(1), '创建【作业】失败!'..operation ) end -- 设置巨星任务状态为执行 N_B_STATE = 1 任务执行 strUpdateSql = "N_B_STATE = 1, S_OP_CODE = '"..operation.code.."'" strCondition = "S_SOURNO = '"..jx_task.sour_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "JX_Task", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then wms.wms_AbortCntrLockTrans( trans_id ) lua.Error( strLuaDEID, debug.getinfo(1), "更新【巨星任务】信息失败!"..strRetInfo ) end end wms.wms_CommitCntrLockTrans( trans_id ) local action = { { action_type = "refresh", value = "" } } mobox.setInfo( strLuaDEID, "成功创建 "..nCount.." 个巨星空料箱出库!" ) nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str( action )) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "setAction错误: "..strRetInfo) end end